import treeService from "../service/tree";
import { codeFail, codeSuccess } from "./resultData";

export default function (app: any) {
    app.get("/apple/tree/list", async (req, res) => {
        const data = await treeService.queryList(req.query.groupId);
        res.send(codeSuccess(data));
    });
    app.get("/apple/tree", async (req, res) => {
        const data = await treeService.queryById(req.query.id);
        res.send(codeSuccess(data[0]));
    });
    app.post("/apple/tree", async (req, res) => {
        const data = await treeService.insert(req.body.data);
        if (!data) {
            return res.send(codeFail("新增失败"));
        }
        res.send(codeSuccess(data));
    });
    app.delete("/apple/tree", async (req, res) => {
        const data = await treeService.deleteById(req.query.id);
        if (!data) {
            return res.send(codeFail("删除失败"));
        }
        res.send(codeSuccess());
    });

    app.put("/apple/tree", async (req, res) => {
        const data = await treeService.update(req.body.data);
        if (!data) {
            return res.send(codeFail("更新失败"));
        }
        res.send(codeSuccess());
    });

    app.get("/apple/tree/notice", async (req, res) => {
        const data = await treeService.queryNoticeNum();
        if (!data) {
            return res.send(codeFail("查询失败"));
        }
        res.send(codeSuccess(data));
    });
}
